package com.sgcc.fj.pmos.e_fj_home.activity;

import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.Lifecycle;
import androidx.viewpager.widget.ViewPager;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.blankj.utilcode.util.GsonUtils;
import com.blankj.utilcode.util.KeyboardUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.flyco.tablayout.SlidingTabLayout;
import com.sgcc.pmos.nativesdk.R;
import com.sgcc.fj.pmos.arouter.home.HomeArouterPath;
import com.sgcc.fj.pmos.common.adapter.HomeTabPagerAdapter;
import com.sgcc.fj.pmos.common.base.BaseActivity;
import com.sgcc.fj.pmos.common.base.IView;
import com.sgcc.fj.pmos.common.http.HttpInterConst;
import com.sgcc.fj.pmos.common.http.HttpRequestUtils;
import com.sgcc.fj.pmos.common.http.MvpNetCallback;
import com.sgcc.fj.pmos.common.utils.AssetsUtil;
import com.sgcc.fj.pmos.common.utils.ImmersionBarUtils;
import com.sgcc.ln.pmos.common.widget.TitleBar;
import com.sgcc.fj.pmos.e_fj_home.bean.MarketUserBean;
import com.sgcc.fj.pmos.e_fj_home.bean.MembersMarketBean;
import com.sgcc.fj.pmos.e_fj_home.fragment.PowerUsersFragment;
import com.sgcc.fj.pmos.e_fj_home.fragment.PowerUsersSearchFragment;
import com.sgcc.fj.pmos.e_fj_home.fragment.SellElectricityCompanyFragment;
import com.sgcc.fj.pmos.e_fj_home.fragment.SellElectricityCompanySearchFragment;
import com.sgcc.fj.pmos.e_fj_mall.activity.MallSearchActivity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import okhttp3.Call;

/**
 * 主体信息
 */
@Route(path = HomeArouterPath.HOME_MEMBERSMARKET_SEARCH)
public class MembersMarketSearchActivity extends BaseActivity {
    private SlidingTabLayout mStlContent;
    private ViewPager mViewpager;
    private final List<Fragment> fragments = new ArrayList<>();
    private HomeTabPagerAdapter homeTabPagerAdapter;
    private LinearLayout content_linner;
    private ImageView back_img;
    private TextView search_txt;
    private EditText search_edit;
    private String inputContent;
    SellElectricityCompanySearchFragment sellElectricityCompanyFragment = new SellElectricityCompanySearchFragment();
    PowerUsersSearchFragment powerUsersFragment = new PowerUsersSearchFragment();

    @Override
    protected int getContentViewLayoutID() {
        return R.layout.activity_membersmarket_search;
    }

    @Override
    protected void initViews() {
        super.initViews();
        findViewByIds();

        String[] titleList = getResources().getStringArray(R.array.membersmarket_title);
        fragments.add(sellElectricityCompanyFragment);
        fragments.add(powerUsersFragment);
        homeTabPagerAdapter = new HomeTabPagerAdapter(getSupportFragmentManager(), fragments);
        homeTabPagerAdapter.setmBottomTabNames(titleList);
        mViewpager.setOffscreenPageLimit(2);
        mViewpager.setAdapter(homeTabPagerAdapter);
        mStlContent.setViewPager(mViewpager);
        mViewpager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {

            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

    private void findViewByIds() {
        back_img = findViewById(R.id.back_img);
        back_img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                MembersMarketSearchActivity.this.finish();
            }
        });
        mStlContent = (SlidingTabLayout) findViewById(R.id.stl_content);
        mViewpager = (ViewPager) findViewById(R.id.viewpager);

        content_linner = findViewById(R.id.content_linner);
        ImmersionBarUtils.initBaseBar(this);
        search_txt = findViewById(R.id.search_txt);
        search_edit = findViewById(R.id.search_edit);
        search_txt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                doSearch();
            }
        });

        search_edit.setOnKeyListener(new View.OnKeyListener() {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                if (keyCode == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_UP) {
                    doSearch();
                }
                return false;
            }
        });


    }


    private void doSearch() {
        KeyboardUtils.hideSoftInput(this);
        inputContent = search_edit.getText().toString();
        content_linner.setVisibility(View.VISIBLE);
        sellElectricityCompanyFragment.setSearchContent(inputContent);
        powerUsersFragment.setSearchContent(inputContent);
    }
}
